package com.mlink.ai.chat.utils

import android.app.ActivityManager
import android.content.Context
import android.os.Process

object ProcessUtil {
    fun getCurrentProcessName(context: Context): String? {
        val runningAppProcesses: List<ActivityManager.RunningAppProcessInfo>?
        val activityManager =
            context.getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager ?: return ""
        runningAppProcesses = activityManager.runningAppProcesses
        if (runningAppProcesses == null) {
            return ""
        }
        val myPid = Process.myPid()
        for (runningAppProcessInfo in runningAppProcesses) {
            if (runningAppProcessInfo.pid == myPid) {
                return runningAppProcessInfo.processName
            }
        }
        return ""
    }
}